export type CloudBaseShortenRegion = 'gz' | 'bj' | 'sh' | 'nj' | 'cd' | 'cq';

export type CloudBaseRegion =
  | 'ap-guangzhou'
  | 'ap-beijing'
  | 'ap-shanghai'
  | 'ap-nanjing'
  | 'ap-chengdu'
  | 'ap-chongqing';

export type CloudBaseConfig = {
  envId: string;
  region?: CloudBaseRegion | string;
  functionRoot: string;
  functions?: ScfConfig[];
};

export type ScfVpc = {
  vpcId: string;
  subnetId: string;
};

// @see https://docs.cloudbase.net/cli-v1/functions/configs
export type ScfConfig = {
  name: string;
  params?: Record<string, unknown>;
  handler?: string;
  ignore?: string | string[];
  timeout?: number;
  envVariables?: Record<string, unknown>;
  vpc?: ScfVpc;
  runtime?: string;
  memorySize?: 128 | 256 | 512 | 1024 | 2048;
  installDependency?: boolean;
  codeSecret?: string;
};

export type ScfConfigCommon = Partial<ScfConfig>;

type PackageOtherProps = {
  [key: string]: unknown;
};

export type PackageCore<T = never> = {
  name: string;
  version: string;
  scripts?: Record<string, string>;
} & PackageOtherProps &
  T;

export type WithScfConfig = {
  scf: ScfConfig;
};

export type WithCloudBaseConfig = {
  cloudbaseConfig: CloudBaseConfig;
  scf: ScfConfigCommon;
};

export type PackageWithCloudBase = PackageCore<WithCloudBaseConfig>;

export type PackageWithScf = PackageCore<WithScfConfig>;
